// TOWN SCRIPT
//    Town 10: Dead Grotto

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,choice;
short lead_char;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered

set_level(6,10);
set_name(6,"Necrophil");

 i = 0;
 while (i < 5) {
  if (char_ok(i)) {
   lead_char = i;
   i = 5;
  }
  else
   i = i + 1;
 }

 set_crime_tolerance(1);

force_instant_terrain_redraw();
if (get_sdf(3,23) == 0) {
 set_flag(3,23,1);
 message_dialog("You come to what was once a very beautiful and serene shrine out here in the forest. Nicely tended rows of trees fill the landscape and clear water channels have been dug out to worship the Nephil gods.","However, something is very wrong. Undead forces have defiled this grotto and transformed it into a playground of rancor and decay.");
}

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;

break;


beginstate 10;

if (get_sdf(3,24) == 0) {
 set_flag(3,24,1);
 message_dialog("This altar was set out to worship some native Nephilim god. Like the rest of this grotto, it too has been descecrated.","");
}

break;


beginstate 11;

if (get_sdf(3,25) == 0) {
 set_flag(3,25,1);
 message_dialog("What a sad site. The Nephil who built this sanctuary put a lot of hard work into making it a place of restoration and healing. Now it is all corrupt. Bones and skeletons are thrown about.","A pool of water for meditation has been tainted and is now foul. A horrid stench hangs in the air, even worse the rest of this grotto.");
}

break;


beginstate 12;

if (get_sdf(3,26) == 0) {
 set_flag(3,26,1);
 message_dialog("Upon inspecting the wall, you stumble into a secret passage. The floor is scalded black and is made of basalt. The smell of sulphur and decay hangs thicker in the air than anywhere else.","You sense the evil magic about this place grow stronger. You must be nearing the source.");
}

break;


beginstate 13;

if (get_sdf(4,2) == 0) {
 set_flag(4,2,1);
 message_dialog("You have penetrated into the chambers of the Nephil necromancer. You take a look around and see a couple of odd crystal containers to the south, both of them have been opened.","A short distance away you see a pedestal containing an alien crystal formation. You think you see speckles of light radiating from within. You wonder where he got these strange objects.");
}

break;


beginstate 14;

reset_dialog();
 add_dialog_str(0,"You sit down and look into the crystal. The speckles are really runed characters. When you look closer, they form into words that you can understand. Do you read them?",0);
 add_dialog_choice(0,"Read the text.");
 add_dialog_choice(1,"Back away.");
 choice = run_dialog(1);
 if (choice == 1) {
  if (get_skill_total(42) >= 12) {
   message_dialog("You peer into the crystal and try to make sense of the writing. It is in a runic dialect you understand, but it is still difficult to decipher. It contains a lot of information on spirits and necromancy.","No doubt, the shaman acquired much of his skill from this. After several minutes of reading, you are able to figure out the instructions an advanced Summon Shade spell.");
   i = 0;
   while (i < 6) {
    if ((get_spell_level(i,1,6) > 0) && (get_spell_level(i,1,6) <= 2))
     change_spell_level(i,1,6,(3 - get_spell_level(i,1,6)));
    i = i + 1;
   }
  }
  else
   message_dialog("You peer into the crystal and try to make sense of the writing. It is in a runic dialect you understand, but it is still difficult to decipher. It contains a lot of information on spirits and necromancy.","No doubt, the shaman acquired much of his skill from this. Unfortunately, your rune reading skill is too deficient to get much of anything out of these alien texts.");
 }
 
break;